package cn.rkylin.oms.system.shop.vo;

import cn.rkylin.oms.system.shop.domain.Shop;
import org.apache.commons.lang.StringUtils;

/**
 * 店铺值对象，用于满足前台展示、系统间交互的需要
 *
 * @author wangxiaoyi
 * @version 1.0
 * @created 13-1月-2017 09:11:15
 */
public class ShopVO extends Shop {
    /**
     * 序列化id
     */
    private static final long serialVersionUID = 1197685576331449588L;

    /*
     * 列表操作按钮定义
     */
    private static final String OPERATION_BTN_EDIT = "<button onclick=\"operationEdit(this)\" shopid=\"%s\" type=\"button\" class=\"btn btn-info btn-xs\"><i class=\"fa fa-edit\"></i>&nbsp;修改</button>";
    private static final String OPERATION_BTN_EDIT_DISABLED = "<button style=\"cursor:default\" disabled shopid=\"%s\" type=\"button\" class=\"btn btn-disable btn-xs\"><i class=\"fa fa-edit\"></i>&nbsp;修改</button>";

    private static final String OPERATION_BTN_ENABLE = "<button onclick=\"operationEnable(this)\" shopid=\"%s\" type=\"button\" class=\"btn btn-success btn-xs\"><i class=\"fa fa-check\"></i>&nbsp;启用</button>";
    // 未验证，不能启用
    private static final String OPERATION_BTN_ENABLE_NOT_VALIDATE = "<button style=\"cursor:dfault\" disabled shopid=\"%s\" type=\"button\" class=\"btn btn-disable btn-xs\"><i class=\"fa fa-check\"></i>&nbsp;启用</button>";
    private static final String OPERATION_BTN_ENABLE_DISABLED = "<button onclick=\"operationEnable(this)\" shopid=\"%s\" type=\"button\" class=\"btn btn-warning btn-xs\"><i class=\"fa fa-ban\"></i>&nbsp;停用</button>";

    private static final String OPERATION_BTN_DELETE = "<button onclick=\"operationDelete(this)\" shopid=\"%s\" type=\"button\" class=\"btn btn-danger btn-xs\"><i class=\"fa fa-trash-o\"></i>&nbsp;删除</button>";
    private static final String OPERATION_BTN_DELETE_DISABLED = "<button style=\"cursor:dfault\" disabled shopid=\"%s\" type=\"button\" class=\"btn btn-disable btn-xs\"><i class=\"fa fa-trash-o\"></i>&nbsp;删除</button>";

    /**
     * 状态定义
     */
    private static final String STATUS_YES = "<span>%s</span>";
    private static final String STATUS_NO = "<span style=\"color:red\">%s</span>";

    /**
     * 项目名称
     */
    private String prjName;
    /**
     * 项目类型
     */
    private String prjType;
    /**
     * 启用状态
     */
    private String status;
    /**
     * 有效状态
     */
    private String validateStatus;
    /**
     * 操作
     */
    private String operation;
    /**
     * orderBy子句
     */
    private String orderBy;
    /**
     * 搜索条件
     */
    private String searchCondition;
    /**
     * 父店铺名称
     */
    private String parentshopname;

    /**
     * 项目简称
     */
    private String prjShortName;
    
    /**
     * 执行开始时间
     */
    private String execStartTime;
    
    /**
     * 执行结束时间
     */
    private String execEndTime;

    public String getPrjShortName() {
        return prjShortName;
    }

    public void setPrjShortName(String prjShortName) {
        this.prjShortName = prjShortName;
    }

    public String getParentshopname() {
        return parentshopname;
    }

    public void setParentshopname(String parentshopname) {
        this.parentshopname = parentshopname;
    }

    public String getPrjName() {
        return prjName;
    }

    public void setPrjName(String prjName) {
        this.prjName = prjName;
    }

    public String getPrjType() {
        return prjType;
    }

    public void setPrjType(String prjType) {
        this.prjType = prjType;
    }

    /**
     * 构造函数
     */
    public ShopVO() {

    }

    public void finalize() throws Throwable {
        super.finalize();
    }

    public String getStatus() {
        StringBuffer statusButton = new StringBuffer();
        if (this.getEnable().equalsIgnoreCase("y")) {
            statusButton.append(String.format(STATUS_YES, "是"));
        } else {
            statusButton.append(String.format(STATUS_NO, "否"));
        }
        return statusButton.toString();
    }

    /**
     * 设置列表上的状态列label
     *
     * @param status
     */
    public void setStatus(String status) {
        this.status = status;
    }

    public String getValidateStatus() {
        return validateStatus;
    }

    public void setValidateStatus(String validateStatus) {
        StringBuffer validateStatusButton = new StringBuffer();
        if (this.getValidate().equalsIgnoreCase("y")) {
            validateStatusButton.append(String.format(STATUS_YES, "是"));
        } else {
            validateStatusButton.append(String.format(STATUS_NO, "否"));
        }
        this.validateStatus = validateStatusButton.toString();
    }

    public String getOperation() {
        return this.operation;
    }

    /**
     * 设置操作列上的按钮
     *
     * @param operation
     */
    public void setOperation(String operation) {
        StringBuffer opButton = new StringBuffer();
        if (StringUtils.isNotEmpty(getShopId())) {
            if (this.getEnable().equalsIgnoreCase("y")) {
                opButton.append(String.format(OPERATION_BTN_EDIT, getShopId()));
                opButton.append("&nbsp;");
                opButton.append(String.format(OPERATION_BTN_ENABLE_DISABLED, getShopId()));
                opButton.append("&nbsp;");
                opButton.append(String.format(OPERATION_BTN_DELETE_DISABLED, getShopId()));
            } else {
                opButton.append(String.format(OPERATION_BTN_EDIT, getShopId()));
                opButton.append("&nbsp;");
                // 验证通过才可以启用，否则不能启用。
                if (this.getValidate().equalsIgnoreCase("y")) {
                    opButton.append(String.format(OPERATION_BTN_ENABLE, getShopId()));
                } else {
                    opButton.append(String.format(OPERATION_BTN_ENABLE_NOT_VALIDATE, getShopId()));
                }
                opButton.append("&nbsp;");
                opButton.append(String.format(OPERATION_BTN_DELETE, getShopId()));
            }
        }
        this.operation = opButton.toString();
    }

    public String getOrderBy() {
        // 此字段需要防止sql注入
        return orderBy == null ? null : orderBy.replaceAll(".*([';]+|(--)+).*", " ");
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public String getSearchCondition() {
        return searchCondition;
    }

    public void setSearchCondition(String searchCondition) {
        this.searchCondition = searchCondition;
    }

	public String getExecStartTime() {
		return execStartTime;
	}

	public void setExecStartTime(String execStartTime) {
		this.execStartTime = execStartTime;
	}

	public String getExecEndTime() {
		return execEndTime;
	}

	public void setExecEndTime(String execEndTime) {
		this.execEndTime = execEndTime;
	}
}